package example1;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-06-23
 * Time: 19:30
 */

public class Coed2 {
    public static void main(String[] args) {
        HashMap<String,Integer> map = new HashMap<>();
        map.put("zhangSan",18);
        map.put("lisi",17);
        map.put("wangWu",16);

        //第一种遍历方式：用迭代器遍历获取map中的key
        //keySet()方法，获取keySet集合，
        //弊：获取不到val值
        Set<String> keySet = map.keySet();
        Iterator<String> iterator = keySet.iterator();
        while(iterator.hasNext()){
            String key = iterator.next();
            System.out.println(key);
        }
        //第二种方式：forEach()循环遍历每一个key
        for(String key: keySet){
            System.out.println(key);
        }
        //第三种方式：最常用的,
        //每一对键值对都是一个Map.Entry,包含key和val
        for(Map.Entry<String,Integer> entry : map.entrySet()){
            System.out.println(entry.getKey());
            System.out.println(entry.getValue());
        }


    }
    public static void main8(String[] args) {
        ArrayList<String> array = new ArrayList<>();
        array.add("zhangSan");
        array.add(0,"lisi");
        for (int i = 0 ; i < array.size() ; i++){
            System.out.println(array.get(i));
        }

        for (String str : array){
            System.out.println(str);
        }
    }
    public static void main7(String[] args) {
        String str2 = "haha";
        System.out.println(str2);

        HashSet<String> set = new HashSet<>();
        set.add("zhangSan"); //添加元素
        set.add("lisi");
        set.add("wangWu");

        String[] array = set.toArray(new String[0]);
        for(int i = 0 ; i < array.length ; i++){
            System.out.println(array[i]);
        }


        Iterator<String> iterator = set.iterator();
        while(iterator.hasNext()){
            String str = iterator.next();
            System.out.println(str);
        }

    }
    public static void main6(String[] args) {
        int num = Integer.parseInt("213213");//不能传入非数字的内容否则会报错
        System.out.println(num);
    }
    public static void main5(String[] args) {
        boolean isUpper = Character.isUpperCase('d');//只能传字符，返回true或者false
        System.out.println(isUpper);
    }
    public static void main4(String[] args) {
        double result = Double.sum(10.0,11.2);//结果为21.2
        System.out.println(result);
    }
    public static void main3(String[] args) {
        int minNum = Integer.min(10, 100);//结果为10
        System.out.println(minNum);
    }
    public static void main2(String[] args) {
        String str = "i love you";
        System.out.println(str.toUpperCase());
    }
    public static void main1(String[] args) {
        String str1 = new String("hello world");
        String str2 = str1.replace("l","被替换");
        System.out.println(str2.toString());
    }
}
